<template>
  <el-button type="danger" :icon="Plus" @click="onSubmit()">新增</el-button>

  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="saleId" label="编号" />
    <el-table-column prop="basicInforId" label="耳号" />
    <el-table-column prop="saleSumMoney" label="成交价(元)" />
    <el-table-column prop="saleMoney" label="定价(元)" />
    <el-table-column prop="saleDiscount" label="折扣比例" />
    <el-table-column prop="saleClass" label="等级" />
    <el-table-column prop="saleType" label="品种" />
    <el-table-column prop="saleSex" label="性别" />
  </el-table>
  <!-- 分页 -->
  <div>
    <el-pagination
      v-model:current-page="adddata.pageIndex"
      v-model:page-size="adddata.pageSize"
      :page-sizes="[3, 5, 8, 10]"
      :background="true"
      layout="total, sizes, prev, pager, next, jumper"
      :total="adddata.totalCount"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script lang="ts" setup>
import axios from "axios";
import { ref, reactive, onMounted } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { useRoute, useRouter } from "vue-router";
import { Delete, Edit, Search, Share, Upload } from "@element-plus/icons-vue";
import type { ComponentSize, FormInstance, FormRules } from "element-plus";
import { Plus } from "@element-plus/icons-vue";
import type { UploadProps, UploadUserFile } from "element-plus";

const apiUrl = import.meta.env.VITE_APP_API_URL;
const apiBedinUrl = import.meta.env.VITE_APPRead_API_URL;

const route = useRoute();
const router = useRouter();
const adddata = reactive({
  pageIndex: 1,
  pageSize: 3,
  totalCount: 0,
  pageCount: 0,
});

const tableData = ref([]);
const gettableData = () => {
  axios
    .post(apiUrl+"/api/Sales/showSale", {
      pageIndex: adddata.pageIndex,
      pageSize: adddata.pageSize,
    })
    .then((res) => {
      tableData.value = res.data.data.list;
      adddata.pageCount = res.data.data.pageCount;
      adddata.totalCount = res.data.data.totalCount;
    });
};
//分页
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  adddata.pageSize = val;
  gettableData();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  adddata.pageIndex = val;
  gettableData();
};
const onSubmit = () => {
  router.push({ name: "AddAblactation" });
};

onMounted(() => {
  gettableData();
});
</script>
